VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmStaff 
   BackColor       =   &H80000002&
   Caption         =   " "
   ClientHeight    =   4635
   ClientLeft      =   3525
   ClientTop       =   2370
   ClientWidth     =   5565
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4635
   ScaleWidth      =   5565
   Begin VB.Frame Frame2 
      BackColor       =   &H00E0E0E0&
      BorderStyle     =   0  'None
      Caption         =   "Frame2"
      Height          =   690
      Left            =   135
      TabIndex        =   12
      Top             =   900
      Width           =   5250
      Begin MSDataListLib.DataCombo CboName 
         Bindings        =   "frmStaff.frx":0000
         Height          =   375
         Left            =   1710
         TabIndex        =   13
         Top             =   165
         Width           =   3270
         _ExtentX        =   5768
         _ExtentY        =   661
         _Version        =   393216
         ForeColor       =   8388736
         ListField       =   "Name"
         BoundColumn     =   "UserCode"
         Text            =   ""
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "VNI-Times"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin VB.Label lbl 
         Alignment       =   2  'Center
         BackColor       =   &H80000002&
         BackStyle       =   0  'Transparent
         Caption         =   "Staff name"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   240
         Index           =   1
         Left            =   330
         TabIndex        =   17
         Top             =   225
         Width           =   1170
      End
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H80000016&
      BorderStyle     =   0  'None
      Height          =   2250
      Left            =   135
      TabIndex        =   5
      Top             =   1665
      Width           =   5265
      Begin VB.TextBox txt_Name 
         DataField       =   "Name"
         DataSource      =   "Adodc1"
         BeginProperty Font 
            Name            =   "VNI-Avo"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800080&
         Height          =   330
         Left            =   1725
         TabIndex        =   14
         Top             =   30
         Width           =   3060
      End
      Begin VB.Label lbl 
         BackColor       =   &H80000002&
         BackStyle       =   0  'Transparent
         Caption         =   "Staff name"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   240
         Index           =   5
         Left            =   465
         TabIndex        =   15
         Top             =   90
         Width           =   1125
      End
      Begin VB.Label lbl 
         BackColor       =   &H80000016&
         Caption         =   "User group"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   240
         Index           =   4
         Left            =   390
         TabIndex        =   11
         Top             =   1500
         Width           =   1140
      End
      Begin VB.Label lbl 
         BackColor       =   &H80000016&
         Caption         =   "User name"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   240
         Index           =   3
         Left            =   450
         TabIndex        =   10
         Top             =   1020
         Width           =   1140
      End
      Begin VB.Label lbl 
         BackColor       =   &H80000016&
         Caption         =   "Staff code"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   240
         Index           =   2
         Left            =   525
         TabIndex        =   9
         Top             =   630
         Width           =   1035
      End
      Begin VB.Label Lbl_GroupName 
         Alignment       =   2  'Center
         BackColor       =   &H80000016&
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800080&
         Height          =   255
         Left            =   1770
         TabIndex        =   8
         Top             =   1485
         Width           =   2865
      End
      Begin VB.Label Lbl_UserName 
         Alignment       =   2  'Center
         BackColor       =   &H80000016&
         DataField       =   "user"
         DataSource      =   "Data1"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800080&
         Height          =   255
         Left            =   1935
         TabIndex        =   7
         Top             =   1050
         Width           =   2805
      End
      Begin VB.Label Lbl_UserCode 
         Alignment       =   2  'Center
         BackColor       =   &H80000016&
         DataField       =   "manv"
         DataSource      =   "Data1"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800080&
         Height          =   255
         Left            =   1920
         TabIndex        =   6
         Top             =   585
         Width           =   2835
      End
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "&Exit"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   465
      Left            =   4485
      TabIndex        =   4
      Top             =   4020
      Width           =   915
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   465
      Left            =   2190
      TabIndex        =   3
      Top             =   4020
      Width           =   1170
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   465
      Left            =   1170
      TabIndex        =   2
      Top             =   4020
      Width           =   1005
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "&Add new"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   465
      Left            =   120
      TabIndex        =   1
      Top             =   4020
      Width           =   990
   End
   Begin VB.CommandButton cmdAdduser 
      Caption         =   "Add &User"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   465
      Left            =   3390
      TabIndex        =   0
      Top             =   4020
      Width           =   1065
   End
   Begin MSAdodcLib.Adodc Adodc2 
      Height          =   330
      Left            =   3495
      Top             =   -105
      Visible         =   0   'False
      Width           =   2130
      _ExtentX        =   3757
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   "sa"
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc2"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   3690
      Top             =   -75
      Visible         =   0   'False
      Width           =   1800
      _ExtentX        =   3175
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   "sa"
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Label lbl 
      BackColor       =   &H80000002&
      BackStyle       =   0  'Transparent
      Caption         =   "Staff Maintenance"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   465
      Index           =   0
      Left            =   150
      TabIndex        =   16
      Top             =   255
      Width           =   3915
   End
End
Attribute VB_Name = "frmStaff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim AnPhim As Byte
Sub mhnvien()
    Lbl_UserCode.Caption = ""
    txt_Name.Text = ""
    Lbl_UserName.Caption = ""
    Lbl_GroupName.Caption = ""
End Sub

Private Sub cboName_Click(Area As Integer)
If Area = 2 Then
    ISEDITING = True
    Dim RecUsers As Recordset
    Set RecUsers = DBconn.Execute("Select * from Users where usercode='" & CboName.BoundText & "'")
    'Adodc1.Recordset.Requery
    
    With RecUsers
        If Not .EOF Then
            txt_Name = !Name
            Lbl_UserCode = !usercode
            Lbl_UserName = IIf(IsNull(!UserName), "", !UserName)
            UserGroup = !UserGroup
        End If
        
        .Close
    End With
    
    If Not IsNull(UserGroup) And UserGroup <> "" Then
        With Adodc2.Recordset
            .MoveFirst
            Do Until !UserGroup = UserGroup
                .MoveNext
                If .EOF Then Exit Do
            Loop
        End With
        Lbl_GroupName.Caption = Adodc2.Recordset("GroupName")
    Else
        Lbl_GroupName.Caption = ""
    End If
End If
ButtonStatus
End Sub

Private Sub cmdCancel_Click()
Adodc1.Recordset.CancelUpdate
'Adodc1.Recordset.Bookmark = Adodc1.Recordset.LastModified
With Adodc2.Recordset
    .MoveFirst
    Do Until !UserGroup = Adodc1.Recordset("UserGroup")
        .MoveNext
        If .EOF Then Exit Do
    Loop
End With
ISADDING = False
ISEDITING = False
ButtonStatus
End Sub

Private Sub cmdSave_Click()
Dim trung As Byte, RecUsers As Recordset
trung = False
Set RecUsers = DBconn.Execute("Select * from Users where Name='" & txt_Name & "'")
If ISADDING Then
    If Not RecUsers.EOF Then trung = True
Else
    If Not RecUsers.EOF Then
     If RecUsers!usercode <> Lbl_UserCode Then trung = True
    End If
End If
If trung Then
    MsgBox "Da co ten nhan vien nay roi. Xem lai"
    Exit Sub
End If
If ISADDING Then
    Lbl_UserCode = PadL(Trim(str(TakeOrderNumber("Staff", True))), 3, "0")
    DBconn.Execute ("Insert into Users (usercode,Name) values ('" & Lbl_UserCode & "','" & txt_Name & "' )")
Else
    DBconn.Execute ("Update Users set Name='" & txt_Name & "' where usercode='" & Lbl_UserCode & "'")
End If

'Adodc1.Recordset("Name") = txt_Name
'Lbl_usercode = Adodc1.Recordset("usercode")
'Adodc1.Recordset.Update
Adodc1.RecordSource = "Users"
Adodc1.Refresh
CboName.ReFill
CboName.Refresh
'Adodc1.Recordset.Bookmark = Adodc1.Recordset.LastModified
ISADDING = False
ISEDITING = False
CboName.BoundText = Lbl_UserCode
CboName.Text = txt_Name
ButtonStatus
End Sub
Sub ButtonStatus()
Frame1.Enabled = ISEDITING
cmdAdd.Enabled = Not ISEDITING
cmdSave.Enabled = ISEDITING
cmdCancel.Enabled = ISEDITING
'cmdExit.Enabled = Not ISEDITING
cmdAdduser.Enabled = Not ISEDITING And NhomLogin = "1"
'txt_Name.Visible = ISADDING Or ISEDITING
CboName.Visible = Not ISADDING
End Sub

Private Sub cmdAdd_Click()
ISADDING = True
ISEDITING = True
ButtonStatus
mhnvien

'Adodc1.Recordset.AddNew
End Sub

Private Sub cmdExit_Click()
Unload frmStaff
End Sub

Private Sub cmdAdduser_Click()
frmAddUser.Show 1
End Sub

Private Sub Form_Load()
    
    ISADDING = False
    ISEDITING = False
    MoFile
    ButtonStatus
End Sub
Sub MoFile()
'BIENCHUNG
'MoDataBase
Adodc1.ConnectionString = ConnectString
Adodc1.ConnectionTimeout = 40
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "Users"
Adodc1.Refresh

Adodc1.Recordset.MoveFirst
With Adodc1.Recordset
    CboName.Text = !Name
    txt_Name.Text = !Name
    Lbl_UserCode = !usercode
    Lbl_UserName = IIf(IsNull(!UserName), "", !UserName)
End With
Adodc2.ConnectionString = ConnectString
Adodc2.ConnectionTimeout = 40
Adodc2.CommandType = adCmdTable
Adodc2.RecordSource = "UserGroup"
Adodc2.Refresh

With Adodc2.Recordset
    .MoveFirst
    Do Until !UserGroup = Adodc1.Recordset("UserGroup")
        .MoveNext
        If .EOF Then Exit Do
    Loop
End With
If Not Adodc2.Recordset.EOF Then Lbl_GroupName.Caption = Adodc2.Recordset("GroupName")

End Sub

Private Sub txt_Name_KeyPress(KeyAscii As Integer)
AnPhim = True
If KeyAscii = 13 Then
    
    cmdSave.SetFocus
End If
End Sub


